package com.mdd.system.controller;

import com.alibaba.fastjson2.JSONArray;
import com.mdd.common.aop.NotPower;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.validate.IdValidate;
import com.mdd.common.validator.annotation.IDMust;
import com.mdd.system.service.ISystemOrganizeService;
import com.mdd.system.validate.SystemOrganizeCreateValidate;
import com.mdd.system.validate.SystemOrganizeSearchValidate;
import com.mdd.system.validate.SystemOrganizeUpdateValidate;
import com.mdd.system.vo.SystemAuthDeptVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("api/system/merchant")
@Api(tags = "系统商户管理（CP、餐饮、洗车、换电）")
public class SystemMerchantController {

    @Resource
    ISystemOrganizeService iSystemAuthDeptService;

    @NotPower
    @GetMapping("/all")
    @ApiOperation(value="商户所有")
    public AjaxResult<List<SystemAuthDeptVo>> all(Long pid) {
        List<SystemAuthDeptVo> list = iSystemAuthDeptService.all( pid,"2");
        return AjaxResult.success(list);
    }

    @GetMapping("/list")
    @ApiOperation(value="商户列表")
    public AjaxResult<JSONArray> list(@Validated SystemOrganizeSearchValidate searchValidate) {
        JSONArray list = iSystemAuthDeptService.list("2",searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="商户详情")
    public AjaxResult<SystemAuthDeptVo> detail(@Validated @IDMust() @RequestParam("id") Long id) {
        SystemAuthDeptVo vo = iSystemAuthDeptService.detail(id);
        return AjaxResult.success(vo);
    }

    @PostMapping("/add")
    @ApiOperation(value="商户新增")
    public AjaxResult<Object> add(@Validated @RequestBody SystemOrganizeCreateValidate createValidate) {
        createValidate.setType(2);
        iSystemAuthDeptService.add(createValidate);
        return AjaxResult.success();
    }

    @PostMapping("/edit")
    @ApiOperation(value="商户编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody SystemOrganizeUpdateValidate updateValidate) {
        iSystemAuthDeptService.edit(updateValidate);
        return AjaxResult.success();
    }

    @PostMapping("/del")
    @ApiOperation(value="商户删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iSystemAuthDeptService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
